let callbacks = [];
let pending = false;
let timerFunc;
function flashCallback() {
    for (let i = 0; i < callbacks.length; i++) {
        let callback = callbacks[i];
        callback();
    }
    // 清空数组，下次进来的时候为0
    callbacks.length = 0;
    pending = false;
}
let p = Promise.resolve();
timerFunc = () => {
    p.then(flashCallback);
}
export function nextTick(cb) {  // 可能是用户调用的nextTick, 也可能是异步更新调用的nextTick
    callbacks.push(cb);
    if (!pending) {
        pending = true;
        timerFunc()
    }
}